CHECKLOGIN=function(){}
CHECKLOGIN.prototype.check = function(){
	var fncSuc = XHR.Delegate(this,this.checkSuc);
	var param = {act:"checklogin"};
	new XHR("post",fncSuc).send($PN+"/DoLogin",param);
}
CHECKLOGIN.prototype.checkSuc=function(r){
	var xml = r.xml;
	if(getRV(xml)){
		var uid = xml.getElementsByTagName("root")[0].getAttribute("uid");
		$("username").innerHTML = "<p><span style='color:blue'>Welcome <b>"+uid+"</b></span></p> " +
				"<p><span style='cursor:pointer;color:black' onClick='showChangePassword()' id='changePassBtn'>[Đổi mật khẩu]</span></p>";
	}else{
		window.location= $PN + "/login.html";
		return;
	}
}
function showChangePassword(){
	var pos = findPos($("changePassBtn"));
	setPos("changepass_div",pos[1],pos[0]-150);
	$("changepass_div").style.display="block";
}
UPDATEPASS=function(){}
UPDATEPASS.prototype.update=function(oldpass,newpass){
	var fncSuc = XHR.Delegate(this,this.updateSuc);
	var param = {oldpass:oldpass,password:newpass};
	new XHR("post",fncSuc).send($PN+"/DoChangePassword",param);
}
UPDATEPASS.prototype.updateSuc=function(r){
	var xml = r.xml;
	if(getRV(xml)){
		alert("Cập nhật thành công");
		$('changepass_div').style.display='none'
	}else{
		window.location="/ProductManager";
		return;
	}
}
function updatePassword(){
	var oldpass = $N("old_password")[0].value;
	var newpass = $N("password")[0].value;
	var c_newpass = $N("c_password")[0].value;
	if(oldpass=="") return;

	if(newpass!=c_newpass || newpass.length <5){
		alert("Mật khẩu không hợp lệ. Tối thiểu 5 ký tự");
		return;
	}
	new UPDATEPASS().update(oldpass,newpass);
}